(: Load the owners, renters, and residential properties :)
let $props := fn:doc("property.xml")/PROPERTIES/RESIDENTIAL_PROPERTY
let $owners := fn:doc("owner.xml")
let $renters := fn:doc("renter.xml")

(: Filter the single-unit two-bedroom properties that are rented :)
let $props_2br_single_rented :=
    for $prop in $props
    where $prop/count(RESIDENTIAL_UNIT) = 1 
        and $prop/RESIDENTIAL_UNIT/@renter
        and $prop/RESIDENTIAL_UNIT[@bedrooms = 2]
    return $prop

for $prop in $props_2br_single_rented,
    $owner in $owners/OWNERS/*,
    $renter in $renters/RENTERS/RENTER
where $owner/@id = $prop/@owner 
    and $renter/@id = $prop/RESIDENTIAL_UNIT/@renter
return <ANS>
        {$prop/ADDRESS}
        <OWNER>{data($owner/NAME)}</OWNER>
        <RENTER>{data($renter/NAME)}</RENTER>
        </ANS>
